<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
		<div class="sub-content">
			<div class="top-header page-header clearfix">
				<h1>Country</h1>
			</div><br/>
		<div class="middle-forms user-profile1 col-md-11">
					<form class="form-horizontal" role="form">
					<div class="sub-forms">
						<div class="form-group">
						 <label class="control-label col-sm-3 ">Country Name</label>
						 <div class="col-sm-9">
						 <input type="text" id="country_name" name="country_name" value="<? if(isset($this->getcontryInfo->country_name)){ echo strtolower($this->getcontryInfo->country_name);}?>" placeholder="Country name"/>
						 </div></div><span id="error_country" style="color:red"></span><br/>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Currency</label>
							<div class="col-sm-9">
							<input type="text" id="currency" name="currency" value="<? if(isset($this->getcontryInfo->currency)){ echo strtolower($this->getcontryInfo->currency);}?>" placeholder="Currency"/>
						</div></div>
						<div class="adding_list form-group">
							<div class="col-sm-3">&nbsp;</div>
							<div class="botton_btns col-sm-9">
								
									<a id="continue"  onclick="return countryValidate();" class="btn btn-danger" role="button">Save</a>
									<a href="<? echo $this->Url('products')?>/all-country-list" class="btn btn-danger" role="button">Back</a>
								
							</div>
						</div>
					</div>
					<span style="color:red" id="add_country"></span>
					<input type="hidden" id="hid_country_id" name="hid_country_id" value="<? if(isset($this->getcontryInfo->country_id)){echo $this->getcontryInfo->country_id;}?>">
					<input type="hidden" id="hid_check" name="hid_check" value="<? if(isset($this->getcontryInfo->country_name)){ echo strtolower($this->getcontryInfo->country_name);}else{echo "0";}?>"/>
		</form>
		</div>
	</div>
</div>
</div>	
<script>
	function countryValidate(){
		var country_name=$("#country_name").val();
		var currency=$("#currency").val();
		var country_id=$("#hid_country_id").val();
		var check_ind_name=$("#hid_check").val();
		if(country_name==""){
			alert("Country name is required");return false;
		}
		if(currency==""){
			alert("Currency is required");return false;
		}
		if(country_id=='' || check_ind_name.toLowerCase()!=country_name.toLowerCase()){
				$.ajax({
				type: 'POST',
				url:BASE_PATH+'/products/check-country-name',
				data:{coun_name:country_name},
				success: function(data){
					if(data.output=='success'){ 
						$("#error_country").html('Country is already exits');return false;
						$("#add_country").html('');
					}else{ 
					$("#error_country").html('');
						$.ajax({
							type: 'POST',
							url: BASE_PATH+'/users/add-country',
							data:{country_name:country_name,country_id:country_id,currency:currency},
							success: function(data){
								if(data.output=='success'){ 
									$("#add_country").html('Successfully added');
									window.location=BASE_URL+'/products/all-country-list';
								}else{ 
									$("#add_country").html('');
								}
							}
						});
					}
				}
			});
		}else{
		window.location=BASE_URL+'/products/all-country-list';
		}
	}
</script>
</html>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>

        